package imper.graphic;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

public class Panel implements DrawableClickable
{
	protected DrawableManager _DrawableManager;
	protected ButtonManager _ButtonManager;
	protected boolean _Active;

	public Panel()
	{
		_DrawableManager = new DrawableManager();
		_ButtonManager = new ButtonManager();
		unActive();
	}

	public Panel( boolean pActive )
	{
		_DrawableManager = new DrawableManager();
		_ButtonManager = new ButtonManager();
		setActive(pActive);
	}

	@Override
	public void draw(GameContainer pGameContainer, Graphics pGraphics) throws SlickException
	{
		if (_Active)
		{
			_DrawableManager.draw(pGameContainer, pGraphics);
		}
	}

	@Override
	public void click(int pX, int pY)
	{
		if (_Active)
		{
			_ButtonManager.click(pX, pY);
		}
	}

	public void addElement(Clickable pClickable)
	{
		_ButtonManager.addClickable(pClickable);
	}

	public void addElement(DrawableClickable pDrawableClickable)
	{
		_ButtonManager.addClickable(pDrawableClickable);
		_DrawableManager.addDrawable(pDrawableClickable);
	}
	
	public void addElement(Drawable pDrawable)
	{
		_DrawableManager.addDrawable(pDrawable);
	}

	public boolean isActive()
	{
		return _Active;
	}

	public void setActive(boolean pActive)
	{
		this._Active = pActive;
	}

	public void active()
	{
		setActive(true);
	}

	public void unActive()
	{
		setActive(false);
	}
	
	public void removeAll()
	{
		_DrawableManager = new DrawableManager();
		_ButtonManager = new ButtonManager();
	}
}
